window.lcs_BtnVol = 0.5
window.lcs_CleVol = 0.5
window.lcs_BtnSort = 0

cc.Class({
    extends: cc.Component,

    properties: {
        startBtn: {
            default: null,
            type: cc.Node
        },
        setBtn: {
            default: null,
            type: cc.Node
        },
        option: {
            default: null,
            type: cc.Node
        },
        closeBtn: {
            default: null,
            type: cc.Node
        },
        btn: {
            default: [],
            type: cc.Node
        }
    },

    touchStart(e){
        e.target.zIndex = 99
    },
    touchMove(e){
        e.target.x += e.getLocationX() - e.getPreviousLocation().x
        e.target.y += e.getLocationY() - e.getPreviousLocation().y
    },
    touchEnd(e){
        e.target.zIndex = e.target._index
        e.target.x = e.target._x
        e.target.y = e.target._y
    },

    onLoad () {
        
        this.startBtn.on('touchstart', this.startGame, this)
        this.setBtn.on('touchstart', this.setGame, this)
        this.closeBtn.on('touchstart', this.closeOption, this)

        for(let i=0; i<this.btn.length; i++){
            this.btn[i].on('touchstart', this.btnStart, this)
            this.btn[i].on('touchmove', this.btnMove, this)
            this.btn[i].on('touchend', this.btnEnd, this)
            this.btn[i].on('touchcancel', this.btnEnd, this)
            this.btn[i]._index = this.btn[i].zIndex
            this.btn[i]._x = this.btn[i].x
            this.btn[i]._y = this.btn[i].y
        }
        
    },
    
    btnStart(e){
        e.target.zIndex = 99
    },

    btnMove(e){
        e.target.x += e.getLocationX() - e.getPreviousLocation().x
        e.target.y += e.getLocationY() - e.getPreviousLocation().y
    },

    btnEnd(e){
        e.target.zIndex = e.target._index
        e.target.x = e.target._x
        e.target.y = e.target._y
    },

    closeOption(){
        this.option.active = false
    },

    setGame(){
        this.option.active = true
    },

    startGame(){
        cc.director.loadScene('Game')
    },

    // start () {    },

    // update (dt) {},
});
